package com.aispeech.testcustom.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.aispeech.testcustom.R;
import com.aispeech.testcustom.TiApplication;
import com.aispeech.testcustom.utils.TiLog;
import com.aispeech.testcustom.utils.UiUtils;

public class WakeupActivity extends AppCompatActivity {

    TextView mTvTitle, mTvResult;
    Switch   mSw;
    Button   mBtnReg;
    ListView mLv;

    boolean isMajorWakeup = true;//默认进入主唤醒词测试 , false则shortcut快捷唤醒测试

    //    @Override
    //    public boolean onCreateOptionsMenu(Menu menu) {
    //        getMenuInflater().inflate(R.menu.menu_wakeup,menu);
    //        return true;
    //    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        //        if (item.getItemId()==R.id.action_wakeup_miss_wakeup){
        //            //误唤醒测试
        //            startActivity(new Intent(WakeupActivity.this,MissWakeupActivity.class));
        //        }else
        if (item.getItemId() == android.R.id.home) {
            WakeupActivity.this.finish();
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wakeup);

        UiUtils.showBack4ActionBar(this, "唤醒测试");

        initView();
        initEvent();

        if (null == TiApplication.getIService()) {
            TiLog.e("no bridgeService!!");
            Toast.makeText(WakeupActivity.this,"没有可以导出的内容!",Toast.LENGTH_SHORT).show();

        }

//        UiUtils.showProgress(this, true, "加载中", "请稍后...");

        //        UiUtils.showProgress(this, true, "加载中", "请稍后...");

        ReadWakeupCmd();
        //        initAiosSdk();
    }

    private void ReadWakeupCmd() {

    }

    //初始化语音接口准备注册指令
    //    private void initAiosSdk() {
    //        AIOSCustomizeManager.getInstance().registerCustomizeListener(new
    // AIOSCustomizeListener() {
    //            @Override
    //            public void onCommandEffect(@NonNull String s) {
    //
    //            }
    //
    //            @Override
    //            public void onShortcutWakeUp(@NonNull String s) {
    //                if ("xiang ge li la".equals(s)){
    //
    //                    AIOSTTSManager.speak("香格里拉");
    //                }else if ("xi ma la ya".equals(s)){
    //
    //                    AIOSTTSManager.speak("喜马拉雅");
    //                }
    //                AIOSTTSManager.speak("快捷唤醒了");
    //            }
    //
    //        });
    //        //定制快捷唤醒词
    //        List<ShortcutWakeup> shortcutWakeupList = new ArrayList<ShortcutWakeup>();
    //        shortcutWakeupList.add(new ShortcutWakeup("香格里拉","xiang ge li la", 0.1f));
    //        shortcutWakeupList.add(new ShortcutWakeup("喜马拉雅","xi ma la ya", 0.1f));
    //        AIOSCustomizeManager.getInstance().registerShortcutWakeups(shortcutWakeupList);
    //    }


    private void initEvent() {
        mSw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                Log.d("test", "sSm onCheckedChanged: isMajorWakeup = " + b);
                mTvTitle.setText(b ? "主唤醒词测试" : "快捷唤醒测试");
                isMajorWakeup = b;
            }
        });
    }

    private void initView() {
        mTvTitle = (TextView) findViewById(R.id.wakeup_tv_title);
        mTvTitle.setText(isMajorWakeup ? "主唤醒词测试" : "快捷唤醒测试");
        mTvResult = (TextView) findViewById(R.id.wakeup_tv_result);
        mSw = (Switch) findViewById(R.id.wakeup_sw_change);
        mBtnReg = (Button) findViewById(R.id.wakeup_btn_register);
        mLv = (ListView) findViewById(R.id.wakeup_lv_container);

    }
}
